home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-17 / devic104.zip / DEVICE.DOC < prev    next >
Text File  |  1991-05-31  |  12KB  |  211 lines

  1. DEVICE -- Program to load/unload a DOS character device driver subsequently
  2.           to system boot as a Terminate-and-Stay-Resident program.
  3.  
  4. DOS Command Syntax (type DEVICE or DEVICE ? for this and other information):
  5.  
  6.   DEVICE <switches> [<filespec> [<params>]]
  7.  
  8. where: <filespec> is the device driver file to load
  9.        <params> are any (optional) parameters needed by the driver
  10.        <options> available:
  11.        <switches> available:
  12.          /? -- Displays this help message
  13.          /p -- Permanently loads device driver (disables unloading)
  14.          /v -- Verifies no duplicate loading of device driver
  15.          /e -- Deallocates environment block (may leave memory hole)
  16.          /u -- Unloads device driver most recently loaded by DEVICE
  17.          /h -- Manually unhooks interrupt vectors still hooked (only with /u)
  18.          /i -- Saves (and restores with /u) interrupt vector contents
  19.  
  20. Effect: Loads a DOS character device driver dynamically after boot time,
  21.         initializes it and links it into the DOS device driver chain,
  22.         emulating the function of IBMDOS.COM in loading DOS device drivers
  23.         while interpreting the CONFIG.SYS file.
  24.  
  25. Returns: ERRORLEVEL 0 => "Successful loading/unloading."
  26.          ERRORLEVEL 1 => "Error -- displayed message indicates reason."
  27.  
  28. Usage Notes:
  29.  * DEVICE is compatible with all known versions of DOS (PC-DOS, MS-DOS,
  30.    Compaq DOS, Seiko DOS, etc.) 3.10 and newer.  It is also compatible with
  31.    most ~100% compatible DOS versions as DR-DOS and the OS/2 compatibility box,
  32.    and DOS-enhancer shells such as 4DOS.
  33.  
  34.  * "Block" type device drivers, i.e., those that provide access to devices
  35.    via a drive letter, such as VDISK, disk partitioners, and CD-ROM devices,
  36.    cannot be loaded by this program.  Only "character" type device drivers
  37.    can be loaded.
  38.  
  39.  * Only device drivers that were previously loaded by DEVICE can be unloaded;
  40.    drivers loaded via CONFIG.SYS or other driver-loaders can't/won't be
  41.    unloaded.
  42.  
  43.    Use the /u switch to unload the most-recently-loaded driver.
  44.  
  45.  * If the same driver is loaded multiple times, each loading will supercede
  46.    the previous; this may or may not cause interaction side-effects, depending
  47.    on how the driver in question behaves in such circumstances.  In any event,
  48.    memory used by prior loadings of the driver will not be reclaimed upon
  49.    subsequent loadings.
  50.  
  51.    Use the /v switch to verify prior to loading a particular driver that
  52.    a driver of the same device name is not already loaded.
  53.  
  54.  * When DEVICE loads a device driver, it links the driver into the DOS
  55.    driver chain, at the front of the chain (just following the NUL device).
  56.    After successful loading and linking, the device driver initialization
  57.    code is invoked via a simulated DOS Initialize Device Request.  The command
  58.    line passed to this request appears as if it would have had IBMDOS loaded
  59.    it: device driver filespec converted to DOS canonical (absolute path) form,
  60.    line contents translated to upper-case, null-terminated, etc.  Any options
  61.    specified to DEVICE will not appear in this command line.
  62.  
  63.    When DEVICE unloads a device driver it issues a Close Device Request to the
  64.    driver, unlinks it from the DOS driver chain, and deallocates the memory
  65.    for the driver.
  66.  
  67.  * Because the usual DOS scheme of deploying device drivers is to load them
  68.    statically and permanently at system boot time, many drivers have not been
  69.    written in anticipation of being unloaded.  Such drivers (e.g., mouse
  70.    drivers, disk-cachers, ANSI.SYS, etc.) often hook interrupt vectors and
  71.    perform other irreversable actions at the time they are loaded and
  72.    initialized; unloading them can cause unpredictable or fatal results.
  73.  
  74.    As described above, when DEVICE unloads a driver it closes the device
  75.    (equivalent to closing a file) before expunging it from the driver chain.
  76.    If the loaded driver has been written such that it allocates resources
  77.    when it receives an Open request and disposes of them upon a Close request,
  78.    rather than allocating them permanently at initialization time, chances
  79.    are that the driver will load and unload hitch-free.
  80.  
  81.    Examples of drivers that load/unload successfully are most communications
  82.    and special-device drivers, some '386 protected-mode drivers (e.g., Borland
  83.    Turbo Debugger's TDH386.SYS), and almost all graphics drivers (e.g. GSS*CGI,
  84.    MetaWINDOW, etc.).
  85.                                             
  86.    Use the /p switch to "permanently" load such device drivers that would
  87.    cause system failure if inadvertently unloaded.
  88.  
  89.  * DEVICE provides two separate strategies for circumventing the inability to
  90.    unload of device drivers because of permanently-hooked interrupts.
  91.  
  92.    Use the /h switch in conjunction with the /u switch when unloading a driver
  93.    to unhook all interrupt vectors hooked by the device driver.  Note that only
  94.    those interrupts which have been hooked in conformance with the official
  95.    BIOS interrupt-sharing convention (as described in the IBM BIOS Interface
  96.    Technical Reference) will be successfully unhooked.  Many drivers do not
  97.    hook interrupt in this fashion; this technique will not succeed with such
  98.    drivers.  The /h switch is ignored unless /u is also specified, or if /i
  99.    was specified (see below) at load time.
  100.  
  101.    Use the /i switch when loading a driver to save the state of all interrupt
  102.    vectors at the time the driver was loaded.  When a driver loaded with the
  103.    /i switch is subsequently unloaded, all interrupt vectors will be restored
  104.    to those original (saved) contents.  This technique adds a penalty of 1K
  105.    additional size to the resident memory requirement of the loaded driver,
  106.    but subsequent unloading should then always succeed as long as the loaded
  107.    driver has no other arcane side-effects upon the DOS operating state.
  108.  
  109.  * Despite some device drivers not being unloadable, virtually all character
  110.    device drivers can still be _loaded_ successfully by DEVICE.  It is thus
  111.    possible to profit by using DEVICE to load such a device driver in a batch
  112.    file prior to invoking an application which needs it, thereby avoiding the
  113.    "edit CONFIG.SYS/reboot shuffle" or the necessity of always loading from
  114.    CONFIG.SYS every one of the myriad drivers that may be needed by various
  115.    applications.
  116.  
  117.    (Additionally, by moving loadable-but-not-unloadable drivers to load via
  118.    DEVICE in AUTOEXEC.BAT instead of CONFIG.SYS, it becomes a simple task
  119.    to create an application-level utility to be run at boot time (subject to
  120.    some condition, say, presence of a keystroke in the buffer) which allows
  121.    the user to select from a menu of drivers to be loaded subsequently.)
  122.  
  123.  * As its first action, DEVICE relocates itself in entirety upward in memory,
  124.    freeing the region just after a tiny nub following its original PSP to
  125.    become the origin where the device driver gets loaded.  This reduces to
  126.    an absolute minimum the resident overhead occupied when loading via DEVICE
  127.    vs. loading directly by IBMDOS.  This overhead consumed is on the order of
  128.    300 bytes or less per driver (the actual size is reported in the HELP
  129.    message).
  130.  
  131.    As a side note of interest, DEVICE does not automatically relocate itself
  132.    as high as possible in contiguous conventional memory.  Such a policy would
  133.    always automatically displace the resident copy of the COMMAND shell present
  134.    there, and require it DOS to reload it every time DEVICE executed.  Instead,
  135.    DEVICE relocates itself 64K beyond its original load origin, loading to the
  136.    highest segment only when limited by available memory.
  137.  
  138.  * The overhead consumed by using DEVICE to load a device driver is in addition
  139.    to any environment space reserved by the TSR.
  140.  
  141.    Use the /e switch to forcibly release this environment space, but be aware
  142.    that freeing environment space that is allocated physically just prior to
  143.    the device driver in memory will not only be unavailable for use, but may
  144.    also cause problems with the DOS memory allocation scheme.
  145.  
  146.  * With the capability to load/unload device drivers via DEVICE, this also
  147.    provides an excellent implementation method for creating resident utilities.
  148.    The DOS device interface offers a natural, relatively full-featured, and
  149.    flexible framework for structuring control and status operations to/from
  150.    the resident utility, with a much higher degree of standardization than
  151.    through the typical TSR approach.
  152.  
  153.  * The maximum memory available to a device driver loadable via DEVICE is
  154.    the lesser of 64K or the amount of conventional memory available, minus
  155.    any stack space used by DEVICE itself (approximately 100h bytes).  Drivers
  156.    exceeding these memory requirements (even temporarily) ought not be loaded
  157.    via DEVICE (unpredictable results may occur).
  158.  
  159.  
  160. Version History:
  161.   0.00 -- Prototype Version
  162.   1.00 -- Initial Release (not distributed):
  163.     * Added code to issue Close Device request to loaded device
  164.       driver when /U (unload) option specified
  165.     * Moved more preparation code into transient area to minimize
  166.       resident size consumed.
  167.   1.01 -- Alpha Test Version:
  168.     * Added /P option for "permanent" loading of DEVICE TSR.
  169.     * Added /V option to skip loading driver(s) redundantly if
  170.       any of them are loaded already.
  171.   1.02 -- First Beta Test Version:
  172.     * Added code to get command-line option indicator character
  173.       from DOS.
  174.     * Added /? option -- treated identically to "?".
  175.     * Added report of size overhead to /? option.
  176.     * Changed options/filespec/params parsing to allow for whitespace
  177.       other than space characters.
  178.     * Added code to convert specified device driver <filespec> passed
  179.       to Initialize Request to absolute form, accounting for current
  180.       drive, directory, and drive substitutions.
  181.     * Moved block device checking into TRANSIENT (clobbered-after-load)
  182.       area to minimize non-essential resident code.
  183.   1.03 -- Second Beta Test Version:
  184.     * Fixed lookup within drive substitution table to accomodate
  185.       table entry size having changed in DOS 4.xx from DOS 3.xx.
  186.     * Changed memory deallocation such that environment block for
  187.       DEVICE TSR is not freed unless /E option is specified (to
  188.       avoid leaving an unallocated "hole" in default case).
  189.   1.04 --
  190.     * Added DOS version number checking, limiting to 3.10 and newer.
  191.     * Revamped code which converts <filespec> to canonical form
  192.       to make use use of undocumented DOS internal function instead.
  193.     * Added startup portion to relocate the loader code to an origin
  194.       64K beyond the PSP, and load the device driver (which must be
  195.       <64K in size) at the PSP to further contract resident code
  196.       to an absolute minimum requirement.
  197.     * Added code to ensure that the driver does not exceed the
  198.       maximum size allowed/available.
  199.     * Added /H switch as supplement to /U to unhook all interrupt
  200.       vectors hooked by the device driver (only those interrupts
  201.       hooked in conformance with the BIOS interrupt-sharing
  202.       convention).
  203.     * Added /I switch to save interrupt vectors for later restoration
  204.       upon unloading the driver.
  205.  
  206. Planned enhancements:
  207.     * Loading/unloading of block device drivers.
  208.  
  209. Copyright (c) 1990-91 by CINCH Enterprises and Rod Pullmann, Boulder, CO.
  210. All rights reserved.  Distributed as Freeware.
  211.